What is the `Array.prototype.flatMap` method in JavaScript?
Description : `flatMap` first maps each element using a mapping function, then flattens the result into a new array.
Answer :
`Array.prototype.flatMap` maps each element using a provided mapping function and then flattens the resulting array into a newarray. It combines the map and flat operations into a single method.const arr =[1,2,3];const flatMapArr = arr.flatMap(x=>[x, x *2]);
console.log(flatMapArr);// [1, 2, 2, 4, 3, 6]
`Array.prototype.flat` creates a newarraywith all sub-array elements concatenated into it recursively up to a specified depth. It can flatten nested arrays to a specified level.const arr =[1,[2,[3,[4]]]];const flatArr = arr.flat(2);
console.log(flatArr);// [1, 2, 3, [4]]
`Array.prototype.flat` creates a newarraywith all sub-array elements concatenated into it recursively up to a specified depth. It can flatten nested arrays to a specified level.const arr =[1,[2,[3,[4]]]];const flatArr = arr.flat(2);
console.log(flatArr);// [1, 2, 3, [4]]
What is the `String.prototype.bold` method in JavaScript?
`String.prototype.bold` returns a string wrapped inHTML`<b>` tags. Note that this method is deprecated and should not be used in modern applications.const str ='hello';const boldStr = str.bold();
console.log(boldStr);// '<b>hello</b>'
`String.prototype.bold` returns a string wrapped inHTML`<b>` tags. Note that this method is deprecated and should not be used in modern applications.const str ='hello';const boldStr = str.bold();
console.log(boldStr);// '<b>hello</b>'